package com.lanou.pianke.admin.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.lanou.pianke.article.entity.Article;
import com.lanou.pianke.admin.mapper.ArticleMapper;
import com.lanou.pianke.admin.service.ArticleService;
import com.lanou.pianke.articlecomment.entity.ArticleComment;
import com.lanou.pianke.common.entity.PiankeResult;
import com.lanou.pianke.common.utils.JsoupUtils;
import org.jsoup.Jsoup;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    @Value("${articleBaseUrl}")
    private String articleBaseUrl;

    @Override
    public List<Article> showAll() {
        String url = articleBaseUrl + "/article/showArticles";
        String data = JsoupUtils.getData(url);

        System.out.println(data);

        List<Article> articles = JSON.parseArray(data, Article.class);
        return articles;
//        return articleMapper.selectAllArticle();
    }

    @Override
    public void deleteByContentId(String contentId) {
        articleMapper.deleteByContentId(contentId);
    }

    @Override
    public void deleteArticleByUid(Long uid) {
        articleMapper.updateStatusByUid(uid);
    }


}
